//
//  ShopCartSuitsViewController.m
//  TryShopping
//
//  Created by panquanReabam.com on 16/10/21.
//  Copyright © 2016年 RuiBen. All rights reserved.
//

#import "ShopCartSuitsViewController.h"

#import "ZJSwitch.h"
#import "MJRefresh.h"
#import "ShopCartSuitsCell.h"
#import "ShopCartSuitsModel.h"
#import "LYDPopViewController1.h"
#import "GetAddBuyGoodsModel.h"
@interface ShopCartSuitsViewController ()<UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UITextViewDelegate,UITableViewDelegate,UITableViewDataSource,LYDPopViewController1Delegate>
@end
@implementation ShopCartSuitsViewController
{
    NSMutableArray*title;
    NSMutableArray*couponId ;
    NSMutableArray*price ;
    NSMutableArray*couponIds ;
    NSMutableArray*headerModelArray ;
    NSString* userToken;
    NSString*planId;
    UIView*noDataView;
     NSString*xuanzhong;
    UITableView*table;
    LYDPopViewController1*popVC;
    NSMutableArray*suitItems;
    NSMutableArray*isCurrentArray;
}
@synthesize alt = alt;

-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
  
     suitItems=[[NSMutableArray alloc]init];
  
}
-(void)update:(NSDictionary *)dic{
    
    headerModelArray=[[NSMutableArray alloc]init];
    isCurrentArray=[[NSMutableArray alloc]init];
    if ([[dic objectForKey:@"ResultInt"] integerValue]==0) {
        [Global hideProgressHUDInternal:self.view];
        
        NSMutableArray *mArray=[NSMutableArray arrayWithArray:[dic objectForKey:@"suits"]];
        for (NSDictionary* dicc in mArray )
        {
            ShopCartSuitsModel *model=[ShopCartSuitsModel mj_objectWithKeyValues:dicc];
            [headerModelArray addObject:model];
            
        }
        [table reloadData];

    }

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBarHidden=NO;
    self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238/255.0 green:238/255.0 blue:238/255.0 alpha:1]];
    lineLabel.alpha=1;
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
//   
    
    UILabel* titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0,40, 23)];
    titleLabel.text=@"促销套餐";
    titleLabel.font=[UIFont systemFontOfSize: 17];
    self.navigationItem.titleView=titleLabel;

    [noDataView removeFromSuperview];
    headerModelArray=[[NSMutableArray alloc]init];
    isCurrentArray=[[NSMutableArray alloc]init];
    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-45) style:UITableViewStylePlain];
    table.delegate = self;
    table.dataSource = self;
    [table registerClass:[ShopCartSuitsCell class] forCellReuseIdentifier:@"ShopCartSuitsViewController"];
    table.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:table];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    userToken = [user objectForKey:@"tokenId"];
    headerModelArray=[[NSMutableArray alloc]init];
    
    planId=@"";
    xuanzhong=@"wu";
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:userToken forKey:@"tokenId"];
    [param setValue:self.shopCartId forKey:@"shopCartId"];
    
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    NSLog(@"-----%@",param);
    [HttpRequest requestData:@"Business/ShopCart/Gifts" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            NSLog(@"-----%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                NSMutableArray *mArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"suits"]];
                if (mArray.count==0) {
                    
                    noDataView=[[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight/2-50, ScreenWidth, 80)];
                    [self.view addSubview:noDataView];
                    UIImageView*noImage=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth/2-47, 0, 94, 51)];
                    noImage.image=[UIImage imageNamed:@"meiyoushuju"];
                    [noDataView addSubview:noImage];
                    UILabel*noLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,65, ScreenWidth, 14)];
                    noLabel.text=@"没有列表数据，赶紧去添加！";
                    noLabel.textColor=zhonghuiColor; noLabel.font=[UIFont systemFontOfSize:14];
                    noLabel.textAlignment=NSTextAlignmentCenter;
                    [noDataView addSubview:noLabel];
                }else{
                    for (NSDictionary* dicc in mArray )
                    {
                        [isCurrentArray addObject:[dicc objectForKey:@"isCurrent"]];
                        ShopCartSuitsModel *model=[ShopCartSuitsModel mj_objectWithKeyValues:dicc];
                        [headerModelArray addObject:model];
                        
                    }
                     for (int i=0; i<isCurrentArray.count; i++) {
                         if ([isCurrentArray[i]isEqualToString:@"Y"]) {
                             xuanzhong=[NSString stringWithFormat:@"%d",i];
                         }
                    }
                    
                    
                }
                    [table reloadData];
                

                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }}
        else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
    }];
    
    UIButton* tureBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, ScreenHeight-45, ScreenWidth, 45)];
    [tureBtn setTitle:@"确认" forState:UIControlStateNormal];
    [tureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    tureBtn.backgroundColor=luseColor;
    CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){204.0/255.0,153.0/255.0, 51.0/255.0, 1.0});
    [tureBtn.layer setBorderColor:tureBTncolorref];//边框颜色
    [tureBtn addTarget:self action:@selector(ture:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:tureBtn];
    
}
-(void)ture:(UIButton*)sender{
    
   
    if ([[Global getJudgeTheErrorStr:planId]isEqualToString:@""]||planId==NULL) {
        [self showAlertMessage:@"请选择商品！"];
    }else{
        NSMutableDictionary *param = [NSMutableDictionary new];
       
        
        [param setValue:userToken forKey:@"tokenId"];
        [param setValue:self.shopCartId forKey:@"shopCartId"];
        [param setValue:planId forKey:@"planId"];
        [param setValue:suitItems forKey:@"suitItems"];
        
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSLog(@"-----%@",param);
        [HttpRequest requestData:@"Business/ShopCart/AddGift" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                NSLog(@"-----%@",severDataDict.dataDict);
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [_mDelegate update:@""];
                    
                    [self.navigationController popViewControllerAnimated:YES];
                }else{
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    [Global showTextHudSub:requestResultStr view:self.view];
                }}
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:severDataDict.resultStr view:self.view];
            }
        }];
        
    }
    
    
}

#pragma mark - Table view data source
#pragma mark - Table view delegate


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat sectionHeaderHeight = 45;
    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=-64) {
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
   ShopCartSuitsModel *groupModel = headerModelArray[section];
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth,45)];
    [view setBackgroundColor:[UIColor whiteColor]];
    if (section==0) {
    }else{
    //UILabel*lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(10, 0, ScreenWidth-20, 0.45)];
    //[lineLabel1 setBackgroundColor:qianhuiColor];
    //[view addSubview:lineLabel1];
    }
    UILabel*lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(10, 45-0.45, ScreenWidth-20, 0.45)];
    [lineLabel setBackgroundColor:qianhuiColor];
    [view addSubview:lineLabel];

    
   
    
    NSString *s1 =[NSString stringWithFormat:@"%@",groupModel.sptypeName];
    UIFont *font1 = [UIFont systemFontOfSize:13];
    CGSize size1 = CGSizeMake(ScreenWidth-60, 2000);
    CGSize labelsize1 = [s1 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
    UILabel*sptypeName=[[UILabel alloc] initWithFrame:CGRectMake(15, 16, labelsize1.width, 13)];
    [sptypeName setText:s1];
    sptypeName.font=[UIFont systemFontOfSize:12];
    sptypeName.backgroundColor=[UIColor colorWithRed:255/255.0 green:51/255.0 blue:0/255.0 alpha:1];
    sptypeName.textAlignment=NSTextAlignmentCenter;
    sptypeName.textColor=[UIColor whiteColor];
    [view addSubview:sptypeName];

    UILabel*conditionsLabel = [[UILabel alloc]initWithFrame:CGRectMake(sptypeName.right+3,0, ScreenWidth, 45)];
    conditionsLabel.font=[UIFont systemFontOfSize:11];
    [view addSubview:conditionsLabel];
    UIButton*chooseBtn1=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth,45)];
    [chooseBtn1 addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
    chooseBtn1.tag=section;
    [view addSubview:chooseBtn1];
    
    
    NSString  *suitPriceStr=[NSString stringWithFormat:@"¥%@",[Global floatConvertPercentile:[groupModel.suitPrice floatValue]]];
    NSString *promotionPriceStr=[NSString stringWithFormat:@"立省¥%@",[Global floatConvertPercentile:[groupModel.promotionPrice floatValue]]];
    NSString *goodInfoStr=[NSString stringWithFormat:@"%@ %@ %@ %@" ,[NSString stringWithFormat:@"%@", @""],groupModel.planTypeName,suitPriceStr,promotionPriceStr];
    
    
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:goodInfoStr];
    NSDictionary * dict = @{
                            NSBackgroundColorAttributeName:[UIColor colorWithRed:255/255.0 green:51/255.0 blue:0/255.0 alpha:1],
                            NSFontAttributeName:[UIFont systemFontOfSize:11],
                            NSForegroundColorAttributeName:[UIColor whiteColor]};
    
    //从下标0开始，长度为2的内容设置多个属性，dict里面写的就是设置的属性
    [AttributedStr setAttributes:dict range:NSMakeRange(0, @"".length)];
    
    NSDictionary * dict1 = @{
                             NSForegroundColorAttributeName:[UIColor colorWithRed:100.0f/255.0f green:100.0f/255.0f blue:100.0f/255.0f alpha:1.0f],
                             NSFontAttributeName:[UIFont systemFontOfSize:12]};
    
    //从下标2开始，长度为6的内容添加多个属性，dict1里面写的就是添加的属性
    [AttributedStr addAttributes:dict1 range:NSMakeRange(@"".length+1, groupModel.planTypeName.length)];
    
    
    NSDictionary * dict2 = @{
                             NSForegroundColorAttributeName:[UIColor blackColor],
                             NSFontAttributeName:[UIFont systemFontOfSize:12]};
    
    //从下标2开始，长度为6的内容添加多个属性，dict1里面写的就是添加的属性
    [AttributedStr addAttributes:dict2 range:NSMakeRange(@"".length+2+ groupModel.planTypeName.length, suitPriceStr.length)];
    
    NSDictionary * dict3 = @{
                             NSForegroundColorAttributeName:[UIColor redColor],
                             NSFontAttributeName:[UIFont systemFontOfSize:12]};
    
    [AttributedStr addAttributes:dict3 range:NSMakeRange(@"".length+3+ groupModel.planTypeName.length+suitPriceStr.length,promotionPriceStr.length)];
    
    conditionsLabel.attributedText = AttributedStr;
    

        if ([[NSString stringWithFormat:@"%@", groupModel.isCurrent]isEqualToString:@"Y"]&&xuanzhong.intValue==section) {
            UIButton*chooseBtn=[[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-40, 7.5, 30, 30)];
            chooseBtn.userInteractionEnabled=NO;
            UIImage *img=[UIImage imageNamed:@"gous"];
            chooseBtn.tag=section;
            [chooseBtn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
            [chooseBtn setImage:img forState:UIControlStateNormal];
            [view addSubview:chooseBtn];
            planId=[NSString stringWithFormat:@"%@", groupModel.planId];
            
            suitItems=[[NSMutableArray alloc]init];
            ShopCartSuitsModel *groupModel = headerModelArray[section];
            if (groupModel.items.count>0) {
                for (int i=0; i<groupModel.items.count; i++) {
                    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                    NSString *itemId = [NSString stringWithFormat:@"%@",[[groupModel.items  objectAtIndex:i]objectForKey:@"itemId"]];
                    NSString *specId =[NSString stringWithFormat:@"%@",[[groupModel.items  objectAtIndex:i]objectForKey:@"specId"]];
                     NSString *pid =[NSString stringWithFormat:@"%@",[[groupModel.items  objectAtIndex:i]objectForKey:@"pid"]];
                    [dic setValue:itemId forKey:@"itemId"];
                      [dic setValue:pid forKey:@"pid"];
                    if ([[NSString stringWithFormat:@"%@",specId ] isEqualToString:@""]) {
                        specId=@"";
                    }else{
                        if ([[NSString stringWithFormat:@"%@",specId ] isEqualToString:@"<null>"]) {
                            specId=@"";
                        }
                        [dic setValue:specId forKey:@"specId"];
                    }
                    [suitItems addObject:dic];
                }
                
            }

          
        }else{
            
            UIButton*chooseBtn=[[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-40, 7.5, 30, 30)];
            chooseBtn.userInteractionEnabled=NO;
            UIImage *img=[UIImage imageNamed:@"quans"];
            chooseBtn.tag=section;
            [chooseBtn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
            [chooseBtn setImage:img forState:UIControlStateNormal];
            [view addSubview:chooseBtn];

            
        
        }
    
    return view;
    
    
}

-(void)chooseBtn:(UIButton*)sender{
    suitItems=[[NSMutableArray alloc]init];
    ShopCartSuitsModel *groupModel = headerModelArray[sender.tag];
    if (groupModel.items.count>0) {
     for (int i=0; i<groupModel.items.count; i++) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        NSString *itemId = [NSString stringWithFormat:@"%@",[[groupModel.items  objectAtIndex:i]objectForKey:@"itemId"]];
        NSString *specId =[NSString stringWithFormat:@"%@",[[groupModel.items  objectAtIndex:i]objectForKey:@"specId"]];
         NSString *pid =[NSString stringWithFormat:@"%@",[[groupModel.items  objectAtIndex:i]objectForKey:@"pid"]];
         [dic setValue:itemId forKey:@"itemId"];
         [dic setValue:pid forKey:@"pid"];
        if ([[NSString stringWithFormat:@"%@",specId ] isEqualToString:@""]) {
            specId=@"";
        }else{
            if ([[NSString stringWithFormat:@"%@",specId ] isEqualToString:@"<null>"]) {
                specId=@"";
            }
            [dic setValue:specId forKey:@"specId"];
        }
        [suitItems addObject:dic];
   

    }

        ShopCartSuitsModel *groupModel = headerModelArray[sender.tag];
        groupModel.isCurrent = @"Y";
        xuanzhong=[NSString stringWithFormat:@"%ld",sender.tag];
        [headerModelArray replaceObjectAtIndex:sender.tag withObject:groupModel];
        [table reloadData];
    }else{
        [self showAlertMessage:@"无套装可选！"];
    
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return headerModelArray.count;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    ShopCartSuitsModel *groupModel = headerModelArray[section];
    return [groupModel.items count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ShopCartSuitsCell*cell = [tableView dequeueReusableCellWithIdentifier:@"ShopCartSuitsViewController"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    if (cell==nil) {
       
    }else{
        while ([cell.contentView.subviews lastObject] != nil) {
            [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];  //删除并进行重新分配
        }
    }
    ShopCartSuitsModel *groupModel = headerModelArray[indexPath.section];

    
    cell.productImageView=[[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 70, 70)];
    cell.productImageView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    cell.productImageView.layer.borderWidth= 0.5f;
    [cell.productImageView setImageWithURL:[NSURL URLWithString:[groupModel.items[indexPath.row]objectForKey:@"imageUrl"]] placeholderImage:[UIImage imageNamed:@"zhengfangxing"]];
    [cell.contentView addSubview:cell.productImageView];
    cell.productNameLabel=[[UILabel alloc] initWithFrame:CGRectMake(95, 16, ScreenWidth-116, 13)];
    [cell.productNameLabel setText:[groupModel.items[indexPath.row]objectForKey:@"itemName"]];
    cell.productNameLabel.font=[UIFont systemFontOfSize:13];
    cell.productNameLabel.textColor=[UIColor colorWithRed:51.0/255.0f green:51.0/255.0f  blue:51.0/255.0f  alpha:1.0];
    [cell.contentView addSubview:cell.productNameLabel];
    
    
    if ([[NSString stringWithFormat:@"%@",  [groupModel.items[indexPath.row]objectForKey:@"specType"]]isEqualToString:@"0"]  ) {
        
    }else{
        NSString *s1 =[NSString stringWithFormat:@"%@",[NSString stringWithFormat:@"%@",  [groupModel.items[indexPath.row]objectForKey:@"specName"]]];
        UIFont *font1 = [UIFont systemFontOfSize:14];
        CGSize size1 = CGSizeMake(ScreenWidth-60, 2000);
        CGSize labelsize1 = [s1 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
        
        cell.productSpecNameLabel=[[UILabel alloc] initWithFrame:CGRectMake(95, 35, labelsize1.width+10, 25)];
        [cell.productSpecNameLabel setText:s1];
        cell.productSpecNameLabel.font=[UIFont systemFontOfSize:12];
        cell.productSpecNameLabel.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
        cell.productSpecNameLabel.layer.borderWidth= 0.5f;
        cell.productSpecNameLabel.textAlignment=NSTextAlignmentCenter;
        cell.productSpecNameLabel.textColor=[UIColor colorWithRed:102.0/255.0f green:102.0/255.0f  blue:102.0/255.0f  alpha:1.0];
        [cell.contentView addSubview:cell.productSpecNameLabel];
    }
    cell.productPriceLabel=[[UILabel alloc] initWithFrame:CGRectMake(95, 72.5, 200, 12)];
    
    
    [cell.productPriceLabel setText:[NSString stringWithFormat:@"¥ %0.02f",[[NSString stringWithFormat:@"%@",  [groupModel.items[indexPath.row]objectForKey:@"dealPrice"]] floatValue]]];
    cell.productPriceLabel.font=[UIFont systemFontOfSize:12];
    cell.productPriceLabel.textColor=[UIColor colorWithRed:102.0/255.0f green:102.0/255.0f  blue:102.0/255.0f  alpha:1.0];
    [cell.contentView addSubview:cell.productPriceLabel];
     cell.productInvLabel=[[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth-125, 72.5, 110, 15)];
    [ cell.productInvLabel setText:[NSString stringWithFormat:@"x %d",[[NSString stringWithFormat:@"%@",  [groupModel.items[indexPath.row]objectForKey:@"quantity"]] intValue]]];
     cell.productInvLabel.font=[UIFont systemFontOfSize:13];
     cell.productInvLabel.textColor=[UIColor colorWithRed:109.0/255.0f green:102.0/255.0f  blue:102.0/255.0f  alpha:1.0];
    NSString *str=[NSString stringWithFormat:@"x %d",[[NSString stringWithFormat:@"%@",  [groupModel.items[indexPath.row]objectForKey:@"quantity"]] intValue]];
    NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:str];
    [attriString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1.0] range:NSMakeRange(0, 2)];
    
     cell.productInvLabel.attributedText=attriString;
     cell.productInvLabel.textAlignment=NSTextAlignmentRight;
    [cell.contentView addSubview: cell.productInvLabel];
    if (groupModel.items.count !=indexPath.row+1) {
        UIImageView *_hengxian = [[UIImageView alloc]initWithFrame:CGRectMake(10,100-0.45, ScreenWidth-20, 0.5)];
        _hengxian.image=[UIImage imageNamed:@"hengxian"];
        [cell.contentView addSubview:_hengxian];
        
    }
    
    if (groupModel.items.count ==indexPath.row+1) {
        UILabel*lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(10, 100-0.45, ScreenWidth-20, 0.45)];
        [lineLabel setBackgroundColor:qianhuiColor];
        [cell.contentView addSubview:lineLabel];

    }
   

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 45;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return  100;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     ShopCartSuitsModel *groupModel = headerModelArray[indexPath.section];
    if ([[NSString stringWithFormat:@"%@",  [groupModel.items[indexPath.row]objectForKey:@"specType"]]isEqualToString:@"0"]  ) {
        
    }else{
        
//         NSLog(@"----%@",groupModel.items[indexPath.row]);
//          NSLog(@"----%@",[groupModel.items[indexPath.row]objectForKey:@"itemId"]);
//          NSLog(@"----%@",[groupModel.items[indexPath.row]objectForKey:@"pid"]);
        popVC=[[LYDPopViewController1 alloc] init];
        popVC.delegate=self;
        popVC.shopCartId=self.shopCartId;
        popVC.planId=groupModel.planId;
        
        popVC.productNameStr=[groupModel.items[indexPath.row]objectForKey:@"itemName"];
        popVC.productURL=[groupModel.items[indexPath.row]objectForKey:@"imageUrl"];
        popVC.pid=[groupModel.items[indexPath.row]objectForKey:@"pid"];
        popVC.itemId=[groupModel.items[indexPath.row]objectForKey:@"itemId"];
        
      
//        popVC.itemId=[groupModel.items[indexPath.row]objectForKey:@"itemId"];
       
//    popVC.productURL=model.imageUrlFull;
//    popVC.productNameStr=model.itemName;
//    popVC.productPriceScopeStr=[NSString stringWithFormat:@"¥%0.02f", [model.salePrice floatValue]];
//    popVC.productStockCountStr=[NSString stringWithFormat:@"%d",[model.invQty intValue]];
//    popVC.itemIDStr=model.itemId;
//    popVC.itemCodeStr=model.itemCode;
//    popVC.typeString=_typeString;
    
//    if ([[Global getType] isEqualToString:@"SCANCASHIER"]) {
//        popVC.countStr=[NSString stringWithFormat:@"%@", model.shopCartQty];
//        //           popVC.countStr= model.specCount;
//    }else{
//        popVC.countStr= model.specCount;
//        
//    }
    
    //    NSLog(@"popVC.typeString====%@",popVC.typeString);
    [popVC show];

//    GetAddBuyGoodsModel *model=headerModelArray[indexPath.row];
//    if ([model.isAvailable isEqualToString:@"Y"]) {
//        for (int i=0;  i<headerModelArray.count; i++) {
//            NSIndexPath *indexPath1 =[NSIndexPath indexPathForRow:i inSection:0 ];
//            UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath1];
//            ShopCartSuitsCell *sharecell=(ShopCartSuitsCell *)cell;
//            [sharecell.chooseBtn1 setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
//        }
//        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
//        ShopCartSuitsCell *sharecell=(ShopCartSuitsCell *)cell;
//        [sharecell.chooseBtn1 setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
//        
//        specId=model.specId;
//        
//    }else{
//        
//        [self showAlertMessage:@"不可以领取！"];
//    }
//    
    }
}
- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}
@end
